#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        vector<int> dp;
        int n = nums.size();
        dp.resize(n);
        dp[0] = nums[0];
        for (int i = 1; i < n; i++) dp[i] = dp[i - 1] + nums[i];
        for (int i = 0; i < n; i++)
        {
            if (dp[i] - nums[i] == dp[n - 1] - dp[i]) return i;
        }
        return -1;
    }
};